package com.info.zhiduoduo.repository.mapper.partner;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.partner.PartnerRecommendCompanyDto;
import com.info.zhiduoduo.repository.entity.partner.PartnerRecommendCompany;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2019-07-30
 */
public interface PartnerRecommendCompanyMapper extends BaseMapper<PartnerRecommendCompany> {

	@Select(" select prc.*,c.compname as actualCompanyName,pa.realname as partnerName " +
			" from zdd_partner_recommend_company prc " +
			" left join zdd_company c on c.compid=prc.actual_companyid " +
			" join zdd_partner_account pa on pa.partnerid=prc.partnerid " +
			" where prc.partnerid=#{partnerid} " +
			" and CONCAT(IFNULL(c.compname,''),prc.recommend_company) like '%${company}%' " +
			" and if(#{state}=0,1=1,prc.state=#{state}) " +
			" order by prc.id desc ")
	List<PartnerRecommendCompanyDto> getRecommendListByPartnerid(@Param("partnerid") int partnerid, @Param("company") String company, @Param("state") int state,
	                                                             @Param("partnerType") int partnerType);

	@Select(" select prc.*,c.compname,pa.realname as partnerName " +
			" from zdd_partner_recommend_company prc " +
			" left join zdd_company c on c.compid=prc.actual_companyid " +
			" join zdd_partner_account pa on pa.partnerid=prc.partnerid " +
			" where prc.id=#{id}")
	PartnerRecommendCompanyDto getRecommendCompany(@Param("id") Integer id);

	@Select(" select pc.id,pa.realname as partnerName,pc.partnerid,pc.compid as actualCompanyid,c.compname as actualCompanyName," +
			" pc.ratio as actualBrokerageRatio,pc.type as actualPartnerType,pc.createtime,pc.updatetime " +
			" from zdd_partner_company pc " +
			" join zdd_company c on c.compid=pc.compid " +
			" join zdd_partner_account pa on pa.partnerid=pc.partnerid " +
			" where pc.partnerid=#{partnerid} " +
			" and c.compname like '%${company}%' " +
			" and pc.deleted = 0 and pc.expiredate >= CURDATE() " +
			" order by pc.updatetime desc  ")
	List<PartnerRecommendCompanyDto> getEffectiveRecommendList(@Param("partnerid") int partnerid, @Param("company") String company, @Param("partnerType") int partnerType);


	@Select(" select prc.*,c.compname as actualCompanyName,pa.realname as partnerName " +
			" from zdd_partner_recommend_company prc " +
			" left join zdd_company c on c.compid=prc.actual_companyid " +
			" join zdd_partner_account pa on pa.partnerid=prc.partnerid " +
			" where CONCAT(IFNULL(c.compname,''),prc.recommend_company) like '%${company}%' " +
			" and if(#{state}=0,1=1,prc.state=#{state}) " +
			" order by prc.updatetime desc ")
	List<PartnerRecommendCompanyDto> getRecommendList(@Param("company") String company, @Param("state") int state, @Param("partnerType") int partnerType);

	@Select(" select pc.id,pa.realname as partnerName,pc.partnerid,pc.compid as actualCompanyid,c.compname as actualCompanyName," +
			" pc.ratio as actualBrokerageRatio,pc.type as actualPartnerType,pc.createtime,pc.updatetime " +
			" from zdd_partner_company pc " +
			" join zdd_company c on c.compid=pc.compid " +
			" join zdd_partner_account pa on pa.partnerid=pc.partnerid " +
			" where c.compname like '%${company}%' " +
			" and pc.deleted = 0 and pc.expiredate >= CURDATE() " +
			" order by pc.updatetime desc  ")
	List<PartnerRecommendCompanyDto> getEffectiveRecommendList(@Param("company") String company, @Param("partnerType") int partnerType);
}
